home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Molotov Cocktail.lua < prev    next >
Text File  |  2010-09-12  |  6KB  |  161 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Molotov Cocktail + Projectile Molotov Cocktail
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, August 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.cocktail={}
  10. cc.cocktail.cocktail={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.cocktail.gfx_wpn=loadgfx("weapons/molotovcocktail.png")                -- Weapon Image
  14. setmidhandle(cc.cocktail.gfx_wpn)
  15. cc.cocktail.sfx_attack=loadsfx("throw.ogg")                                -- Attack Sound
  16.  
  17. --------------------------------------------------------------------------------
  18. -- Weapon: Molotov Cocktail
  19. --------------------------------------------------------------------------------
  20.  
  21. cc.cocktail.id=addweapon("cc.cocktail","Molotov Cocktail",cc.cocktail.gfx_wpn,1,2)    -- Add Weapon (1 use, first in round 2)
  22.  
  23. function cc.cocktail.draw()                                                -- Draw
  24.     if weapon_shots<=0 then
  25.         setblend(blend_alpha)
  26.         setalpha(1)
  27.         setcolor(255,255,255)
  28.         drawinhand(cc.cocktail.gfx_wpn,6,0)
  29.     end
  30.     -- HUD chargebar
  31.     if weapon_charge>0 and weapon_shots==0 then
  32.         hudchargebar(weapon_charge,100)
  33.     end
  34.     -- HUD Crosshair
  35.     if weapon_shots==0 then
  36.         hudcrosshair(4,3)
  37.     end
  38. end
  39.  
  40. function cc.cocktail.attack(attack)                                        -- Attack
  41.     if (weapon_shots<=0) then
  42.         -- Charge
  43.         if (attack==1) then
  44.             weapon_charge=weapon_charge+1                                -- Increase charge
  45.         end
  46.         -- Fire a projectile (on release/full charge)
  47.         if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
  48.             -- No more weapon switching!
  49.             useweapon(0)
  50.             playsound(cc.cocktail.sfx_attack)
  51.             weapon_shots=weapon_shots+1
  52.             id=createprojectile(cc.cocktail.cocktail.id)
  53.             projectiles[id]={}
  54.             -- Ignore collision with current player at beginning
  55.             projectiles[id].ignore=playercurrent()
  56.             -- Set initial position of projectile
  57.             projectiles[id].x=getplayerx(0)+(4*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
  58.             projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
  59.             -- Set speed of projectile
  60.             projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  61.             projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
  62.             -- Set timer
  63.             projectiles[id].timer=1
  64.             -- Effects
  65.             recoil(2)
  66.             -- End Turn
  67.             endturn()
  68.         end
  69.     end
  70. end
  71.  
  72. --------------------------------------------------------------------------------
  73. -- Projectile: Molotov Cocktail
  74. --------------------------------------------------------------------------------
  75.  
  76. cc.cocktail.cocktail.id=addprojectile("cc.cocktail.cocktail")    -- Add Projectile
  77.  
  78. function cc.cocktail.cocktail.draw(id)                            -- Draw
  79.     -- Setup draw mode
  80.     setblend(blend_alpha)
  81.     setalpha(1)
  82.     setcolor(255,255,255)
  83.     setscale(1,1)
  84.     -- Calculate projectile rotation
  85.     setrotation(math.deg(math.atan2(math.abs(projectiles[id].sx),-projectiles[id].sy)))
  86.     -- Draw projectile
  87.     drawimage(cc.cocktail.gfx_wpn,projectiles[id].x,projectiles[id].y)
  88.     -- Draw Arrow if out of Screen
  89.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  90. end
  91.  
  92. function cc.cocktail.cocktail.update(id)                        -- Update
  93.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  94.     -- Particle Tail
  95.     particle(p_smoke,projectiles[id].x,projectiles[id].y)
  96.     particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
  97.     particlefadealpha(0.01)
  98.     particle(p_lightpuff,projectiles[id].x,projectiles[id].y)
  99.     particlefadealpha(0.04)
  100.     if getframe()%3==1 then
  101.         particle(p_spark,projectiles[id].x,projectiles[id].y)
  102.     end
  103.     -- Gravity influence on speed
  104.     projectiles[id].sy=projectiles[id].sy+getgravity()
  105.     -- Move (in substep loop for optimal collision precision)
  106.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  107.     msubx=projectiles[id].sx/msubt
  108.     msuby=projectiles[id].sy/msubt
  109.     for i=1,msubt,1 do
  110.         -- Move X
  111.         projectiles[id].x=projectiles[id].x+msubx
  112.         if collision(col5x5,projectiles[id].x,projectiles[id].y)==1 then
  113.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  114.                 projectiles[id].timer=0
  115.             end
  116.         else
  117.             projectiles[id].ignore=0
  118.         end
  119.         -- Move Y
  120.         projectiles[id].y=projectiles[id].y+msuby
  121.         if collision(col5x5,projectiles[id].x,projectiles[id].y)==1 then
  122.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  123.                 projectiles[id].timer=0
  124.             end
  125.         else
  126.             projectiles[id].ignore=0
  127.         end        
  128.         -- Water
  129.         if (projectiles[id].y)>getwatery()+5 then
  130.             -- Effects
  131.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  132.             playsound(sfx_hitwater1)
  133.             -- Free projectile
  134.             freeprojectile(id)
  135.             break
  136.         end
  137.     end
  138.     -- Explode
  139.     if projectiles[id].timer<=0 then
  140.         -- Cause damage
  141.         arealdamage(projectiles[id].x,projectiles[id].y,100,15)
  142.         -- Destroy terrain
  143.         terrainexplosion(projectiles[id].x,projectiles[id].y,15,1)
  144.         -- Crater
  145.         grey=math.random(0,40)
  146.         if math.random(0,1)==1 then
  147.             terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  148.         else
  149.             terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
  150.         end
  151.         -- Fire
  152.         createobject(o_fire,projectiles[id].x,projectiles[id].y)
  153.         for a=45,360,45 do
  154.             createobject(o_fire,projectiles[id].x+math.sin(math.rad(a))*35,projectiles[id].y-math.cos(math.rad(a))*35)
  155.         end
  156.         -- Free projectile
  157.         freeprojectile(id)
  158.     end
  159.     -- Scroll to projectile
  160.     scroll(projectiles[id].x,projectiles[id].y)
  161. end